package br.ufpe.cin.wormbox.protocolo;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import br.ufpe.cin.wormbox.exceptions.RPFTSocketException;

public class TesteClient {
	
	public static void main(String[] args) throws InterruptedException, IOException, RPFTSocketException {
		RPFTSocket sock = new RPFTSocket("localhost", 5000);
		RPFTPacket packet;
		byte[] dados;
		
		System.out.println("Conectado");
		try {
			File f = new File("RAR3GB.rar");
			f.createNewFile();
			FileOutputStream fos = new FileOutputStream(f);
			
			do {
				packet = sock.receber();
				dados = packet.getDados();
				
				if(dados.length > 1) {
					fos.write(dados);
				}
			} while(dados.length > 1);
			System.out.println("cabou :P");
		} catch (FileNotFoundException e) {
			e.printStackTrace();
			System.exit(0);
		} catch (IOException e) {
			e.printStackTrace();
			System.exit(0);
		}
		
		sock.disconnect();
	}
	
}

//1958036

//1269297
